<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\admin\controller;

use app\common\controller\Backend;

/**
 * 审核规则类
 *
 * @author Administrator
 */
class Auditpolicy extends Backend {

    protected $model = null;

    public function _initialize() {
        parent::_initialize();
        $this->model = model('Auditpolicy');
    }

    public function index() {
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('pkey_name')) {
                return $this->selectpage();
            }
            $task_id = $this->request->param('task_id');
            $model = $this->model;
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $total = $model
                    ->where('task_id', $task_id)
                    ->order($sort, $order)
                    ->count();
            $list = $model
                    ->where('task_id', $task_id)
                    ->order($sort, $order)
                    ->limit($offset, $limit)
                    ->select();
            $result = array("total" => $total, "rows" => $list);
            return json($result);
        }


        $task_id = $this->request->param('ids');
        $this->view->assign('task_id', $task_id);
        return $this->fetch();
    }

    public function dels($ids = "") {
        if ($ids) {
            $pk = $this->model->getPk();
            $adminIds = $this->getDataLimitAdminIds();
            if (is_array($adminIds)) {
                $count = $this->model->where($this->dataLimitField, 'in', $adminIds);
            }
            $list = $this->model->where($pk, 'in', $ids)->select();
            $count = 0;
            foreach ($list as $k => $v) {
                $count += $v->delete();
            }
            if ($count) {
                $this->success();
            } else {
                $this->error(__('No rows were deleted'));
            }
        }
        $this->error(__('Parameter %s can not be empty', 'ids'));
    }

}
